using UnityEngine;
using System.Collections;

public class DrillPoint : Point {
	public float drillSpeed = 1.0f;
	public LockPoint lockTowards;
	
	// Constructor
	public DrillPoint() {
		setColorCenter(Color.yellow);
		setColorForward(Color.red);
		setColorUp(Color.grey);
	}
	
	// Start is called at the first frame
	void Start() {
		if (transform.parent != null
		&&  lockTowards 	 != null) {
			
			Entity parent = transform.parent.GetComponent<Entity>();
			if (parent != null) {
				parent.setLocalPoint(GetComponent<LockPoint>());
				parent.setTargetPoint(lockTowards);
				parent.transform.parent = lockTowards.transform.parent;
				parent.updateLock();
			} else {
				Debug.LogWarning("DrillPoint must reside exactly one step below drill tip entity.");
			}
			
		} else {
			Debug.LogWarning("Found a DrillPoint attached to nothing.");
		}
	}
	
	// Update is called once per frame
	void Update () {
		if (transform.parent != null) {
			Entity parent = transform.parent.GetComponent<Entity>();
			if (parent != null) {
				if (parent.isLocked()) {
					if (parent.getLocalPoint() == GetComponent<LockPoint>()) {
						//parent.getLocalPoint().transform.RotateAround(parent.getLocalPoint().transform.forward, Time.deltaTime * drillSpeed);
						//parent.getTargetPoint().transform.RotateAround(parent.getTargetPoint().transform.forward, Time.deltaTime * drillSpeed);
						parent.transform.RotateAround(transform.forward, Time.deltaTime * drillSpeed);
					}
				}
			}
		}
	}
}
